import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.0
import OGLQApp 0.0

Item {
	property var item
	signal itemSelected(var data)

	id: root

	Label {
		id: loadingLabel
		text: "Loading…"
	}
	Loader {
		id: uiLoader
		width: parent.width
		height: parent.height
	}
	GLItemLoader {
		id: itemLoader
		onLoaded: {
			console.log("load");
			console.log(item);
			loadingLabel.visible = false
			uiLoader.setSource("ItemView.qml", {item: JSON.parse(item), allowFetch: false});
			console.log(height);
		}
		onFailed: {
			loadingLabel.text = "Error: " + err
			console.error("error");
			console.error(err);
		}
	}
	Component.onCompleted: {
		itemLoader.load(item.uri);
	}
	Connections {
		target: uiLoader.item
		onItemSelected: {
			itemSelected(data);
		}
	}
}
